upstream django_app {
    # for a file socket
    server unix:/opt/{project_name}-env/{project_name}.sock;
    # for a web port socket
    # server 127.0.0.1:8001;
}

server {
    # the port your site will be served on
    listen      80;

    # Django 的 settings.py 文件中的 ALLOWED_HOSTS 要加上这里设置的 server_name
    server_name localhost
    charset     utf-8;

    gzip on;
    gzip_min_length 1000;
    gzip_buffers 4 16k;
    gzip_http_version 1.1;
    gzip_comp_level 3;
    gzip_vary on;
    # 禁用对 IE 6 使用 gzip 压缩
    gzip_disable "MSIE [1-6]\.";
    gzip_types text/plain text/css text/xml application/javascript text/javascript application/x-javascript application/xml application/xml+rss application/json;

    ## Individual nginx logs
    access_log  /var/log/nginx/{project_name}/access.log;
    error_log   /var/log/nginx/{project_name}/error.log;

    # max upload size
    client_max_body_size 8M;   # adjust to taste

    location /ngx_status{
        stub_status on;
        access_log off;
        #allow 127.0.0.1;
        #deny all;
    }

    # location ~ .*\.(css|js)$ {
    #   add_header Cache-Control no-store;
    # }

    location ~ ^/favicon\.ico$ {
        root    /opt/{project_name}-env/{project_name}/static;
    }

    # Django media
    location /media/  {
        alias /opt/{project_name}-env/{project_name}/media/;
    }

    location /static/ {
        alias /opt/{project_name}-env/{project_name}/static/;
    }

    # api doc
    location /api-doc/  {
        alias /opt/{project_name}-env/{project_name}/api-doc-build/;
        index   index.html;
    }

    # Finally, send all non-media requests to the Django server.
    location ~ ^(/api/|/admin/) {
    # location / {
        add_header 'Access-Control-Allow-Origin' * always;
        add_header 'Access-Control-Allow-Credentials' 'true' always;
        add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, PATCH, OPTIONS' always;
        add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,token' always;

        if ($request_method = 'OPTIONS') {
            return 204;
        }

        uwsgi_pass  django_app;
        # the uwsgi_params file you installed
        # 增加 nginx 配置， uwsgi_params 文件在 /etc/nginx/ 目录下
        include     /etc/nginx/uwsgi_params;
        uwsgi_connect_timeout    75;
        uwsgi_read_timeout 1800;
        uwsgi_send_timeout 300;
        proxy_read_timeout 300;
    }
}